package com.cr.mrapp.configurer;

import com.cr.mrapp.Interceptor.SessionInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfigurer implements WebMvcConfigurer {
    private static final String UPLOADED_FOLDER = System.getProperty("user.dir");
    @Autowired
    private SessionInterceptor sessionInterceptor;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/**")
                .addResourceLocations("file:///"+UPLOADED_FOLDER+"/upload/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(sessionInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/static/**","/**/*.js","/upload/**","/user/login.do","/page/login","/api/**");
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
